package baby.myroute.activity;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;

import com.baidu.mapapi.GeoPoint;
import com.baidu.mapapi.MapView;
import com.baidu.mapapi.MyLocationOverlay;

public class MyOverlay extends MyLocationOverlay
{

	private Bitmap myPhoto;
	private Paint paint;
	private String name;
	private boolean nameVisible;

	public MyOverlay(Context paramContext, MapView paramMapView, String name,boolean nameVisible)
	{
		super(paramContext, paramMapView);
		this.name = name;
		this.nameVisible=nameVisible;
		myPhoto = BitmapFactory.decodeResource(paramContext.getResources(), R.drawable.pop1);
		this.paint = new Paint();
		paint.setColor(Color.RED);
		paint.setTextSize(20);
		this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
		this.paint.setAntiAlias(true);

	}

	@Override
	protected void drawMyLocation(Canvas paramCanvas, MapView paramMapView, Location paramLocation, GeoPoint paramGeoPoint, long paramLong)
	{
		super.drawMyLocation(paramCanvas, paramMapView, paramLocation, paramGeoPoint, paramLong);
		
		if (paramGeoPoint == null)
			return;
		
		
		
		
		if(nameVisible)
		{
			Point localPoint = paramMapView.getProjection().toPixels(paramGeoPoint, null);
			int i1 = localPoint.x - this.myPhoto.getWidth() / 2;
			int i2 = localPoint.y - this.myPhoto.getHeight();

			paramCanvas.drawBitmap(this.myPhoto, i1, i2, null);
			paramCanvas.drawText(name, i1 + 2, i2 + 22, paint);
		}
		

	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public boolean isNameVisible()
	{
		return nameVisible;
	}

	public void setNameVisible(boolean nameVisible)
	{
		this.nameVisible = nameVisible;
	}
	
}
